# -*- coding:utf-8 -*-

# @Time : 2023/5/9 14:39
# @Author : 快乐的小猴子
# @Version : 
# @Function : 

import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By


class GetCookies:

    def get_cookies(self, url):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get(url)
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div[1]/div[4]/div/div[1]/div[2]/a[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '//*[@id="loginBox_page"]/div[1]/ul/li[2]').click()
        time.sleep(0.2)
        driver.find_element(By.ID, 'userId').send_keys('496040838573')
        time.sleep(0.2)
        # driver.find_element(By.XPATH, '//*[@id="passWordPH"]').send_keys('090909')
        # time.sleep(0.2)
        driver.find_element(By.XPATH, '//*[@id="loginProtocol"]').click()
        time.sleep(6)
        driver.find_element(By.ID, 'mem_btn_login').submit()
        time.sleep(10)
        cookies = driver.get_cookies()
        with open('./conf/cookies.txt', 'w', encoding='UTF-8') as fp:
            fp.write(json.dumps(cookies))
        print('cookies保存成功！！！')
